import { loginByTestPhoneAPI } from "@/api/profile";
export default {
  namespaced: true,
  state: {
    profile: null,
    token: "666",
    userInfo: {
      username: "tom",
      mobile: "13233333333",
      roles: {
        menus: ["权限一", "权限二"],
      },
    },
  },
  getters: {
    value: (state) => {
      return state.value;
    },
  },
  mutations: {
    setToken(state, payload) {
      state.token = payload;
    },
    saveProfile(state, payload) {
      console.log("state, payload  ----->  ", state, payload);
      state.profile = payload;
    },
  },
  actions: {
    // 2. 声明action方法
    async loginByTestPhone({ commit }) {
      const { result } = await loginByTestPhoneAPI("13577778888");
      // 3. 调用mutation修改方法
      commit("saveProfile", result);

      uni.showToast("登录成功");
      setTimeout(() => {
        uni.navigateBack();
      }, 1500);
    },
  },
};
